﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CreateAndExport
{
    public partial class EmployeeForm : Form
    {
        private string comName;
        private string departName;
        public EmployeeForm()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Form2 choosePerson = new Form2();
            choosePerson.LoadData(
        }

        private void EmployeeForm_Load(object sender, EventArgs e)
        {
            var entities = new DbDataContext();
            cbb_Company.DataSource = entities.Companies.Select(c => c.Name);
        }

        private void cbb_Company_SelectedIndexChanged(object sender, EventArgs e)
        {
            var entities = new DbDataContext();
            var selectedText = ((ComboBox)sender).SelectedItem;
            cbb_Department.DataSource = entities.Departments.Where(d => d.Company1.Name.Equals(selectedText)).Select(d => d.Name);
            if (cbb_Department.Items.Count == 0) {
                cbb_Department.Text = "";
            }
        }
    }
}
